import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/pages/nft_pages/setting/setting_controller.dart';
import 'package:yysk_app/routes/global_controller.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/button_widget.dart';
import 'package:yysk_app/widget/input_widget.dart';
import 'package:yysk_app/widget/verification_code_widet.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'package:yysk_app/widget/custom_app_bar2.dart';
import 'package:yysk_app/net/api/api_url.dart';

class ModifyPassword extends StatelessWidget {
  static String path = '/modifyPassword';

  ModifyPassword({super.key});
  final SettingController controller = Get.find();
  final GlobalController globalController = Get.find();
  final TextEditingController onePwdontroller = TextEditingController();
  final TextEditingController twoPwdController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    double top = MediaQuery.of(context).padding.top;
    return PopScope(
      canPop: false,
      child: Scaffold(
        backgroundColor: AppColors.backgroundColorBlack,

        resizeToAvoidBottomInset: false,
        body: SafeArea(
          top: false,
          child: Stack(
            children: [
              Positioned.fill(
                top: 0.px,
                left: 0,
                child: ImageAssetWidget(
                  imageUrl: 'static/images/bg2.png',
                  width: 375.px,
                  height: 812.px,
                  fit: BoxFit.fitWidth,
                  alignment: Alignment.topCenter,
                ),
              ),
              Column(
                children: [
                  SizedBox(height: top),
                  CustomAppBar2(title: '', context: context),

                  Padding(
                    padding: EdgeInsets.fromLTRB(24.px, 38.px, 24.px, 0.px),

                    child: Column(
                      children: [
                        Row(
                          children: [
                            hiSpace(width: 8.px),
                            Text(
                              '设置登录密码',
                              style: TextStyle(
                                fontSize: 24.px,
                                color: AppColors.fontColor,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ],
                        ),
                        hiSpace(height: 71.px),
                        InputWidget(
                          disabled: true,
                          hint: '${globalController.user.value?.userTel}',
                          backgroundColor: AppColors.backgroundColorBlackLight,
                          buttonRadio: 24,
                          inputType: TextInputType.number,
                          onChanged: (value) {},
                        ),
                        hiSpace(height: 12.px),
                        VerificationCodeWidet(
                          initialCount: 60,
                          buttonRadio: 24,
                          type: VerificationCodeType.RESET_PASSWORD,
                          phoneNumber:
                              globalController.user.value?.userTel ?? '',
                          onChanged: ({String? code, int? msgId}) {
                            if (code != null && code != '') {
                              controller.changeValue(code, 'codes');
                            }
                            controller.changeValue(msgId, 'smsId');
                          },
                        ),
                        hiSpace(height: 12.px),
                        InputWidget(
                          hint: '支持8-18位，由数字和字母组成',
                          // errorText: controller.pwdErrorOne.value,
                          controller: onePwdontroller,
                          backgroundColor: AppColors.backgroundColorBlackLight,
                          buttonRadio: 24,
                          onChanged: (value) {
                            if (value.length < 19) {
                              controller.changeValue(
                                value.length > 18
                                    ? value.substring(0, 18)
                                    : value,
                                'pwd',
                              );
                            } else {
                              //或者输入上一次数据
                              onePwdontroller.value = TextEditingValue(
                                text: controller.pwd!, // 截断到 11 位
                                selection: TextSelection.collapsed(
                                  offset: controller.pwd!.length,
                                ), // 光标移动到末尾
                              );
                            }
                          },
                          obscureText: true,
                          visible: true,
                        ),
                        hiSpace(height: 12.px),
                        InputWidget(
                          hint: '再次确认密码',
                          backgroundColor: AppColors.backgroundColorBlackLight,
                          buttonRadio: 24,
                          // errorText: controller.pwdErrorTwo.value,
                          controller: twoPwdController,
                          onChanged: (value) {
                            if (value.length < 19) {
                              controller.changeValue(
                                value.length > 18
                                    ? value.substring(0, 18)
                                    : value,
                                'againPwd',
                              );
                            } else {
                              //或者输入上一次数据
                              twoPwdController.value = TextEditingValue(
                                text: controller.againPwd!, // 截断到 11 位
                                selection: TextSelection.collapsed(
                                  offset: controller.againPwd!.length,
                                ), // 光标移动到末尾
                              );
                            }
                          },
                          obscureText: true,
                          visible: true,
                        ),
                      ],
                    ),
                  ),
                  hiSpace(height: 64.px),
                  ButtonWidget(
                    height: 47.px,
                    width: 327.px,
                    fontSize: 16.px,
                    fontWeight: FontWeight.w500,
                    label: '确定',
                    onPressed: () {
                      controller.modifyPassword();
                    },
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
